#include <iostream>
using std::cout;
using std::endl;

class Complex
{
public:
    Complex(int real,int image)
    : _real(real)
    , _image(image)
    {}

    void print() const{
        cout << _real << " + "
            << _image << "i"
            << endl;
    }

    Complex & operator=(const Complex & rhs)
    {
        _real = rhs._real;
        _image = rhs._image;
        return *this;
    }

    //多个运算符重载函数之间还存在函数重载的空间
    /* Complex & operator=(int x){} */
    /* Complex & operator=(double x){} */

    //成员函数形式实现重载
    Complex operator+(const Complex & rhs){
        return Complex(_real + rhs._real,
                       _image + rhs._image);
    }
private:
    int _real;
    int _image;
};

//error
/* Complex & operator=(Complex & cx,int x){} */

void test0(){
    int x = 1, y = 2;
    /* &(x + y); */
    cout << x + y << endl;


    Complex cx1(1,2);
    Complex cx2(3,4);
    /* cx1 = cx2; */
    /* cx1.operator=(cx2); */
   
    //本质形式
    /* Complex cx3 = cx1.operator+(cx2); */
    Complex cx3 = cx1 + cx2;
    cx3.print();
}

int main(void){
    test0();
    return 0;
}
